
import http from '@/utils/http.js'
import api from '@/api/api.js'

const state = {
	user: uni.getStorageSync('user'),
	token: uni.getStorageSync('token'),
	mobile: '',
}

const mutations = {
	SET_TOKEN: (state, token) => {
	  state.token = token
	  uni.setStorageSync('token', token)
	},
	SET_USER: (state, info) => {
	  state.user = info
	  uni.setStorageSync('user', info)
	},
	SET_MOBILE: (state, mobile) => {
	  state.mobile = mobile
	}
}

const actions = {
	
	login({ commit }, param) {
		return http.getAction(
			api.login, 
			param, 
			(data) => {
				commit('SET_TOKEN', data.jwt)
				commit('SET_USER', data.user)
			}
		)
	},
	
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}